package com.education.realtime.util;

import org.wltea.analyzer.core.IKSegmenter;
import org.wltea.analyzer.core.Lexeme;

import java.io.IOException;
import java.io.StringReader;
import java.util.ArrayList;
import java.util.HashSet;
import java.util.List;


public class IkUtil {
    
    public static List<String> split(String kw) throws IOException {
    
        ArrayList<String> result = new ArrayList<>();
        
        // string -> reader
        // 内存流
        StringReader reader = new StringReader(kw);
        IKSegmenter seg = new IKSegmenter(reader, true);
        //我是中国人
        Lexeme next = seg.next();
    
        while (next != null) {
            String word = next.getLexemeText();
            result.add(word);
            next = seg.next();
        }
    
    
        HashSet<String> set = new HashSet<>(result);
        result.clear();
        result.addAll(set);
    
        return result;
    }
    
    public static void main(String[] args) throws IOException {
        // 电脑 小米电脑 小米高级电脑
        System.out.println(split("大数据数据库" +
                ""));
    }
}
